﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:local="clr-namespace:MVVMFramework.View">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/MVVMFramework.View;component/Themes/Common.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <LinearGradientBrush x:Key="PopupDarkBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FFA3AEB9" Offset="0" />
        <GradientStop Color="#FF8399A9" Offset="0.375" />
        <GradientStop Color="#FF718597" Offset="0.375" />
        <GradientStop Color="#FF617584" Offset="1" />
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PopupBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        <LinearGradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Offset="0" Color="#FFffffff" />
                <GradientStop Offset="1" Color="#FFE8EBED" />
            </GradientStopCollection>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>

    <!-- =============================================================================== -->
    <!-- DateTimePicker                                                                  -->
    <!-- =============================================================================== -->

    <Style TargetType="{x:Type local:DateTimePicker}">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Background" Value="{x:Static SystemColors.WindowBrush}"/>
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{StaticResource CommonBorderBrush}"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
        <Setter Property="TextAlignment" Value="Right" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:DateTimePicker}">
                    <Grid SnapsToDevicePixels="True">
                        <Border x:Name="Background" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                            <Grid Grid.IsSharedSizeScope="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition SharedSizeGroup="ToggleButton" Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <local:ButtonSpinner x:Name="Spinner"
                                             IsTabStop="False"
                                             BorderThickness="0" 
                                             UpButtonBorderThickness="1,0,0,1" DownButtonBorderThickness="1,1,0,0"
                                             Background="{TemplateBinding Background}"
                                             AllowSpin="{TemplateBinding AllowSpin}"
                                             ShowButtonSpinner="{TemplateBinding ShowButtonSpinner}">
                                    <AdornerDecorator>
                                        <TextBox x:Name="TextBox"
                                                 Margin="0"
                                                 BorderThickness="0" 
                                                 Background="Transparent"
                                                 FontFamily="{TemplateBinding FontFamily}" 
                                                 FontSize="{TemplateBinding FontSize}" 
                                                 FontStretch="{TemplateBinding FontStretch}"
                                                 FontStyle="{TemplateBinding FontStyle}" 
                                                 FontWeight="{TemplateBinding FontWeight}" 
                                                 Foreground="{TemplateBinding Foreground}" 
                                                 HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                 IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
                                                 MinWidth="20"
                                                 AcceptsReturn="False"
                                                 Padding="0"
                                                 TextAlignment="{TemplateBinding TextAlignment}"
                                                 TextWrapping="NoWrap" 
                                                 TabIndex="{TemplateBinding TabIndex}"
                                                 Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" >
                                            <local:WatermarkService.Watermark>
                                                <TextBlock Text="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:WatermarkService.Watermark>
                                        </TextBox>
                                    </AdornerDecorator>
                                </local:ButtonSpinner>

                                <ToggleButton x:Name="_calendarToggleButton"
                                      BorderThickness="1,0,0,0" Grid.Column="1"
                                      Background="{x:Static SystemColors.WindowBrush}"
                                      BorderBrush="Transparent"
                                      Visibility="{Binding ShowDropDown,  RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfTrue}}"
                                      IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"
                                      Template="{StaticResource DropDownToggleButtonStyle}"
                                      IsHitTestVisible="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolInvenrse}}"
                                      IsEnabled="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BoolInvenrse}}"/>
                            </Grid>

                        </Border>
                        <Popup IsOpen="{Binding IsChecked, ElementName=_calendarToggleButton}" StaysOpen="False">
                            <Border BorderThickness="1" Background="{StaticResource PopupBackgroundBrush}" BorderBrush="{StaticResource PopupDarkBorderBrush}" Padding="3">
                                <StackPanel>
                                    <Calendar x:Name="PART_Calendar" BorderThickness="0">
                                        <Calendar.Resources>
                                            <Style TargetType="{x:Type Button}">
                                                <Setter Property="MinWidth" Value="0"/>
                                            </Style>
                                        </Calendar.Resources>
                                    </Calendar>
                                    <local:TimePicker x:Name="PART_TimeUpDown"
                                                Visibility="{TemplateBinding ShowTimePicker, Converter={StaticResource VisibleIfTrue}}"
                                                Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                                Foreground="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" 
                                                Format="{TemplateBinding TimeFormat}"
                                                FormatString="{TemplateBinding TimeFormatString}"
                                                Value="{Binding Value, RelativeSource={RelativeSource TemplatedParent}}"
                                                Watermark="{TemplateBinding TimeWatermark}"
                                                WatermarkTemplate="{TemplateBinding TimeWatermarkTemplate}" />
                                </StackPanel>
                            </Border>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" TargetName="Background" Value="#FFF7F7F7"/>
                            <Setter Property="Background" TargetName="_calendarToggleButton" Value="#FFF7F7F7"/>
                            <Setter Property="BorderBrush" TargetName="Background" Value="{StaticResource DisabledBorderBrush}"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" TargetName="_calendarToggleButton" Value="#FF3399FF"/>
                            <Setter Property="Background" TargetName="_calendarToggleButton" Value="{StaticResource HoverInnerBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Background" Value="#FF3399FF"/>
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" TargetName="_calendarToggleButton" Value="#FF3399FF"/>
                            <Setter Property="BorderThickness" TargetName="_calendarToggleButton" Value="1,0,0,0"/>
                            <Setter Property="Background" TargetName="_calendarToggleButton" Value="{StaticResource HoverInnerBackgroundBrush}"/>
                            <Setter Property="BorderBrush" TargetName="Background" Value="#FF3399FF"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>